from src.data import DataSeq
import time

def InsertionSort(ds,v):
    assert isinstance(ds, DataSeq), "Type Error"

    Length = ds.length
    for i in range(Length):
        tmp = ds.data[i]
        j = i
        while j >= 1 and ds.data[j - 1] > tmp:
            ds.SetVal(j, ds.data[j - 1])
            j -= 1
        ds.SetVal(j, tmp)
        time.sleep(v)


def create_sort(title, v, l):
    ds = DataSeq(l, sort_title=title)
    ds.Visualize()
    ds.StartTimer()
    InsertionSort(ds, v)
    ds.StopTimer()
    ds.SetTimeInterval(0)
    # ds.Visualize()
    time.sleep(3)
    ds.destory()
    return 0

if __name__ == "__main__":
    ds = DataSeq(64)
    ds.Visualize()
    ds.StartTimer()
    InsertionSort(ds)
    ds.StopTimer()
    ds.SetTimeInterval(0)
    ds.Visualize()
